package com.open.capacity.employee.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.model.SysRole;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.employee.service.EmployeeService;
import com.open.capacity.log.annotation.LogAnnotation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/employee")
@Api(tags = "职工管理")
public class EmployeeController {
    @PostMapping("/test")
    public Result postTest(){
        return Result.succeed("好笑吗，甘霖凉");
    }

    @Autowired
    private EmployeeService employeeService;

    /**
     * 后台管理查询相关用户
     * @param params
     * @return
     * @throws JsonProcessingException
     */
    @GetMapping("/employee")
    @ApiOperation(value = "后台管理查询相关用户")
    @LogAnnotation(module="employee-center",recordRequestParam=false)
    public PageResult<SysRole> findEmployee(@RequestParam Map<String, Object> params) throws ControllerException {
        try {
            return employeeService.findEmployee(params);
        } catch (ServiceException e) {
            throw new ControllerException(e);
        }
    }

}
